package com.example.remsad;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		final ListView listview = (ListView) findViewById(R.id.listview);
		String[] values = new String[]{ "Android", "iPhone", "WindowsMobile",
		        "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
		        "Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux",
		        "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2",
		        "Android", "iPhone", "WindowsMobile" };
		
		final ArrayList<String> list = new ArrayList<String>();
		for(int i = 0; i < values.length; i++){
			list.add(values[i]);
		}
		
		final StableArrayAdapter adapter = new StableArrayAdapter(this, android.R.layout.simple_list_item_1, list);
		listview.setAdapter(adapter);
		

		
		
		
		/*Intent intent = getIntent();
		String message = intent.getStringExtra("message");*/
		
		/*TextView tv = new TextView(this);
		tv.setText(message);
		setContentView(tv);*/
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

class StableArrayAdapter extends ArrayAdapter<String>{
	HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();
	public StableArrayAdapter(Context context, int textViewResourceId, List<String> object){
		super(context, textViewResourceId, object);
		for(int i = 0; i< object.size();i++){
			mIdMap.put(object.get(i), i);
		}
	}
	
	@Override
	public long getItemId(int position){
		String item = getItem(position);
		return mIdMap.get(item);
	}
	
	@Override
	public boolean hasStableIds(){
		return true;
	}
}
